package com.liang.maogouyuyin.widget.popup

import android.content.Context
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.liang.maogouyuyin.R
import com.liang.maogouyuyin.bean.PetBean
import com.liang.maogouyuyin.ui.adapter.PetAdapter
import com.lxj.xpopup.core.CenterPopupView

class SelectPetPopup(context: Context): CenterPopupView(context) {

    private lateinit var adapter: PetAdapter
    private lateinit var list: ArrayList<PetBean>
    private var listener: PetAdapter.SelectListener? = null

    override fun getImplLayoutId(): Int {
        return R.layout.popup_select_pet
    }

    override fun onCreate() {
        super.onCreate()

        val recyclerview = findViewById<RecyclerView>(R.id.item_select_pet_recyclerview)
        recyclerview.layoutManager = LinearLayoutManager(context)
        adapter = PetAdapter(context)
        adapter.setPopup(this)
        adapter.setList(list)
        listener?.let { adapter.setSelectListener(it) }
        recyclerview.adapter = adapter
    }

    fun setList(list: ArrayList<PetBean>): SelectPetPopup {
        this.list = list
        return this
    }

    fun setListener(listener: PetAdapter.SelectListener): SelectPetPopup {
        this.listener = listener
        return this
    }
}